package vms.data;

import java.io.ByteArrayInputStream;
import java.util.Vector;

import vms.utils.xml.Element;
import vms.utils.xml.LightXmlParser;

public class LinkManager {
	private static LinkManager instance;
	private static int currentLink = -1;
	Vector links = new Vector();
	
	public String getLink(){
		if(links == null || links.size() == 0)
			return null;
		
		currentLink++;
		if(currentLink >= links.size())
			currentLink = 0;
		return (String) links.elementAt(currentLink);
	}
	
	public void parseLinks(byte[] data){
		try {
			Element element = LightXmlParser.parse(new ByteArrayInputStream(data), "UTF-8");
			element = element.getElement("links");
			for (int i = 0;i< element.getChildCount();i++){
				Element link = element.getElement(i);
				links.addElement(link.getAttributeValue("link"));
				System.out.println("ADDLINK: " + link.getAttributeValue("link"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static LinkManager getInstance() {
		if(instance == null)
			instance = new LinkManager();
		return instance;
	}

	public Vector getLinks() {
		// TODO Auto-generated method stub
		return links;
	}
}
